require 'json'

require_relative 'LoginService'
require_relative 'UploadService'
require_relative 'UpdateService'

filesToUpload = {
	'production' => ARGV[1],
	'debug' => ARGV[0]
}
fileMap = JSON.load(File.open(ARGV[2], "r"))

p "Authenticating user"
loginService = LoginService.new
loginService.fireService
assertion = loginService.assertion
p "Login successful"

uploadService = UploadService.new assertion
updateService = UpdateService.new assertion
filesToUpload.each do |key, filePath|
	file = File.open(filePath, "r")
	fileName = File.basename(filePath)
	uploadTo = fileMap[fileName][key]
	p "Uploading file #{key} to #{uploadTo}"
	uploadService.upload file, uploadTo
	url = uploadService.url
	updateService.update uploadTo, url
	p "Uploaded successfully"
end